﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.CopsBanditsUI.OfficerCellStates {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import Events.*;
    import flash.utils.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.util.*;
    import Modules.workers.*;
    import Modules.bandits.*;
    import Display.*;
    import Display.ValentineUI.*;
    import Display.CopsBanditsUI.*;
    import flash.text.*;
    import org.aswing.event.*;
    import Display.aswingui.*;
    import L10n.*;

    public class GenericOfficerState extends JPanel {

        protected var m_officer:CopData;
        protected var m_color:int;
        protected var m_pos:int;
        protected var m_donut:Boolean = false;
        protected var m_cell:OfficerCell;
        public var m_buttonInsets:Insets;
        protected var m_cop:Player;
        protected var m_timeLeft:JTextField;
        protected var m_nextActiveTimer:Timer;

        public function GenericOfficerState(_arg1:CopData, _arg2:int, _arg3:OfficerCell){
            this.m_buttonInsets = new Insets(3, 5, 3, 5);
            super(new BorderLayout());
            this.m_cell = _arg3;
            this.m_color = _arg2;
            if (_arg1 != null){
                this.m_officer = _arg1;
                this.m_pos = this.m_officer.getPosition();
                this.m_donut = (this.m_officer.getState() == CopData.STATE_PATROLLING);
                if (this.m_officer.getZID().charAt(1) == "-"){
                    this.m_cop = Global.player.findFriendById("-1");
                } else {
                    this.m_cop = Global.player.findFriendById(this.m_officer.getZID().substr(1));
                };
            };
            this.init();
        }
        protected function init():void{
            var _local5:Sprite;
            var _local1:JPanel = new JPanel(new BorderLayout());
            var _local2:JPanel = ASwingHelper.makeFlowJPanel(FlowLayout.RIGHT, 10);
            var _local3:JPanel = ASwingHelper.makeFlowJPanel(FlowLayout.LEFT);
            _local2.appendAll(this.makeActionPanel(), this.makeDonutPanel());
            _local3.appendAll(this.makeImagePanel(), this.makeNamePanel());
            ASwingHelper.prepare(_local2);
            var _local4:int = ((OfficersScrollingList.ROW_HEIGHT - _local2.getHeight()) / 2);
            ASwingHelper.setEasyBorder(_local2, _local4, 0, 0, 10);
            _local1.append(_local3, BorderLayout.WEST);
            _local1.append(_local2, BorderLayout.EAST);
            if ((this.m_color % 2) == 0){
                _local5 = new Sprite();
                _local5.graphics.beginFill(EmbeddedArt.lightBlueTextColor);
                _local5.graphics.drawRect(0, 0, 595, 50);
                _local5.graphics.endFill();
                ASwingHelper.setBackground(_local1, _local5);
            };
            _local1.setPreferredWidth(595);
            _local1.setMinimumWidth(595);
            _local1.setMaximumWidth(595);
            this.append(_local1);
        }
        protected function makeImagePanel():JPanel{
            var imageAsset:* = null;
            var ap:* = null;
            var jp:* = ASwingHelper.makeFlowJPanel(FlowLayout.LEFT);
            imageAsset = (new (CopsDialog.assetDict["police_slot_unfilled"])() as DisplayObject);
            if (this.m_cop){
                LoadingManager.load(this.m_cop.snUser.picture, function (_arg1:Event):void{
                    imageAsset = (_arg1.target.loader as DisplayObject);
                    ap.setAsset(imageAsset);
                });
            };
            ap = new AssetPane(imageAsset);
            jp.append(ap);
            return (jp);
        }
        protected function makeNamePanel():JPanel{
            var _local2:String;
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP, -5);
            if (this.m_cop){
                _local2 = this.m_cop.snUser.name;
            };
            var _local3:JLabel = ASwingHelper.makeLabel(_local2, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 14, EmbeddedArt.brownTextColor);
            LocaleHelper.localSetting.JLabel_setFont(_local3, EmbeddedArt.SYSTEM_FONT, 14);
            var _local4:JPanel = ASwingHelper.makeFlowJPanel(FlowLayout.LEFT);
            _local4.append(_local3);
            _local1.append(_local4);
            var _local5:String = ("Cops_position" + String(this.m_officer.getPosition()));
            var _local6:JLabel = ASwingHelper.makeLabel(ZLoc.t("Dialogs", _local5), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 14, EmbeddedArt.blueTextColor);
            var _local7:JPanel = ASwingHelper.makeFlowJPanel(FlowLayout.LEFT);
            _local7.append(_local6);
            _local1.append(_local7);
            return (_local1);
        }
        protected function makeActionPanel():JPanel{
            var _local1:JPanel = ASwingHelper.makeFlowJPanel(FlowLayout.LEFT);
            return (_local1);
        }
        protected function makeDonutPanel():JPanel{
            var _local2:DisplayObject;
            var _local3:AssetPane;
            var _local4:Sprite;
            var _local1:JPanel = ASwingHelper.makeFlowJPanel(FlowLayout.LEFT);
            if (this.m_donut){
                _local2 = (new (CopsDialog.assetDict["police_doughnut"])() as DisplayObject);
                _local3 = new AssetPane(_local2);
            } else {
                _local4 = new Sprite();
                _local2 = (new (CopsDialog.assetDict["police_doughnut_empty"])() as DisplayObject);
                _local4.addChild(_local2);
                _local4.addEventListener(MouseEvent.CLICK, this.askDonut, false, 0, true);
                _local3 = new AssetPane(_local4);
            };
            _local1.append(_local3);
            return (_local1);
        }
        protected function askDonut(_arg1:MouseEvent):void{
            var _local2:GenericDialog = new GenericDialog(ZLoc.t("Dialogs", "Cops_donutmessage"), "", GenericDialogView.TYPE_CUSTOM_OK, this.sendDonutsFeed, "", "", true, 0, "", null, ZLoc.t("Dialogs", "Cops_button_getdonuts"));
            UI.displayPopup(_local2);
            BanditUtil.logDialogStats("empty_donut", "station_ui");
            BanditUtil.logDialogStats("view", "empty_donut_popup");
        }
        protected function sendDonutsFeed(_arg1:GenericPopupEvent):void{
            var _local2:Boolean;
            if (_arg1.button == GenericDialogView.YES){
                _local2 = Global.world.viralMgr.sendGetDonut();
                if (!_local2){
                    UI.displayMessage(ZLoc.t("Dialogs", "Cops_feedMax"), GenericDialogView.TYPE_OK);
                    BanditUtil.logDialogStats("view", "request_limit_ui");
                } else {
                    BanditUtil.logDialogStats("get_donut", "empty_donut_popup");
                };
            } else {
                BanditUtil.logDialogStats("X", "empty_donut_popup");
            };
        }
        protected function rebuildEvent():void{
        }
        protected function getTimeLeft():Number{
            return (0);
        }
        protected function changeCellState():void{
        }
        protected function doAction(_arg1:AWEvent):void{
        }
        protected function changeState():void{
        }
        protected function updateTimerString(_arg1:TimerEvent):void{
            var _local3:TextFormat;
            var _local2:Number = this.getTimeLeft();
            if (_local2 <= 0){
                this.changeState();
            } else {
                this.m_timeLeft.getTextField().text = GameUtil.formatMinutesSeconds(this.getTimeLeft());
                _local3 = this.m_timeLeft.getTextFormat();
                _local3.align = TextFormatAlign.RIGHT;
                this.m_timeLeft.setTextFormat(_local3);
                dispatchEvent(new Event(MakerPanel.PREPARE, true));
            };
        }

    }
}//package Display.CopsBanditsUI.OfficerCellStates 
